/**
 * 
 */
package com.neusoft.cmsprojects.listener;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.enterprise.inject.New;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.struts2.ServletActionContext;

import com.neusoft.cmsprojects.util.TempFileManager;

/**
 * 时间监听器
 * 
 * @author xiaoqun.yi
 */
public class TempFileListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub
		// 删除临时文件夹及文件
		String root = ServletActionContext.getServletContext().getRealPath("/");
		root = root.replaceAll("%20", " ");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String strdate = sdf.format(new Date());
		String path = root + "tempFiles\\" + strdate + "\\"; // 服务器路径
		Calendar calendar = Calendar.getInstance();
		calendar.add(calendar.DATE, 1);
		Date d = calendar.getTime();
		String newdate = sdf.format(d);
		String newpath = root + "tempFiles\\" + newdate + "\\"; // 服务器路径
		TempFileManager tempFileManager = new TempFileManager(root, newpath);
		tempFileManager.start();
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		// TODO Auto-generated method stub

	}

}